home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- ChooserLDEF.c
-
- DESCRIPTION
- Contains code for LDEF resource used by the Chooser.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 10/04/95 - David Hayward - Version 1.0.4 modified code so that
- the driver can be build under MPW,
- Metrowerks, and Symantec. In general,
- all that was required to do this was
- to add an inline-assembly jumptable
- and to store all globals off of the
- message manager instance context.
- Also made a few changes so that the
- driver can be rebuilt to support any
- resolution by changing the #defines
- kResolution and kPatStretch in
- "CommonDefines.h"
-
- 06/14/95 - Dave Hersey - Version 1.0.3 to fix a bug in
- CustomBufferingAndIO.c when creating
- high-res PICTs, and to make the size
- of buffers more flexible.
-
- 05/26/95 - Dave Hersey - Version 1.0.2 to add the new 'outp'
- desktop printer resource in NewApp.c.
-
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Created from the shell of a hollowed-out
- ImageWriter driver.
- */
-
- #include <Lists.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDrawText.h>
- #include <ToolUtils.h>
- #include <LowMem.h>
- #include <GXPrinting.h>
- #include "ChooserLDEF.h"
-
-
- pascal void main (short message, Boolean select, Rect *theRect,
- Cell theCell, short dataOffset, short dataLen, ListHandle theList);
-
-
- /* -----------------------------------------------------------------------
- LDEF is our driver's Chooser LDEF.
-
- This is an LDEF that simply plots an icon, and lets the user "Create."
-
- ----------------------------------------------------------------------- */
-
- pascal void main (
- short message, // What operation to perform on list
- Boolean select, // Is this cell to be selected or not?
- Rect *theRect, // Rectangle of this cell, clipped to window
- Cell theCell, // Which cell this is
- short dataOffset, // Offset into data for this cell
- short dataLen, // Length of data for this cell
- ListHandle theList) // The list to act upon
- {
- #pragma unused (theCell, dataOffset, dataLen)
-
- Handle cicnHdl;
- Rect iconRect;
- char userPrompt[] = "\pPrint to Disk";
-
- switch (message)
- {
- case lInitMsg:
- {
- Cell aCell = {0, 1};
- (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
-
- if ((*theList)->userHandle)
- {
- DetachResource((*theList)->userHandle);
- LSetCell((Ptr) &userPrompt[1], userPrompt[0], aCell, theList);
- LSetSelect(true, aCell,theList);
- }
- }
- break;
-
- case lCloseMsg:
- if ((*theList)->userHandle)
- {
- DisposeCIcon((CIconHandle) (*theList)->userHandle);
- (*theList)->userHandle = nil;
- }
- break;
-
- case lHiliteMsg:
- case lDrawMsg:
- cicnHdl = (*theList)->userHandle;
- if (cicnHdl == nil) break;
-
- // draw the cell as an icon
- // center the icon rect on the list with a top margin of 10 pixels
-
- iconRect.top = theRect->top + 10;
- iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
- iconRect.bottom = iconRect.top + 32;
- iconRect.right = iconRect.left + 32;
-
-
- // draw the icon
-
- if (cicnHdl != nil)
- PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
-
- // Get the general area under the icon in which to draw the label
-
- iconRect.left = theRect->left + 2;
- iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
- iconRect.top = iconRect.bottom + 2;
- iconRect.bottom = theRect->bottom;
-
- // use a nice small font for the label
-
- TextFont(applFont);
- TextSize(9);
-
- {
- short labelWidth;
- short rectWidth;
- short labelHeight;
- FontInfo theInfo;
- unsigned char theHilightMode;
-
- /* Get rid of any previous label, compute the height of the new label,
- compute where to draw the text, truncate the string to fit within the box,
- compute the new width of the string, center the string, and draw it.
- */
- EraseRect(&iconRect);
- iconRect.top += 2;
-
- GetFontInfo(&theInfo);
- labelHeight = theInfo.ascent +theInfo.leading;
-
- iconRect.bottom = iconRect.top + labelHeight;
- rectWidth = iconRect.right-iconRect.left;
-
- // Not very localizable... Use resources in the real world.
-
- TruncString(rectWidth, (unsigned char *) userPrompt, smTruncEnd);
- labelWidth = StringWidth((unsigned char const *) userPrompt);
-
- iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
- MoveTo(iconRect.left, iconRect.bottom);
- DrawString((unsigned char const *) userPrompt);
-
- // If selecting the icon, highlight the text.
-
- if (select)
- {
- iconRect.right = iconRect.left + labelWidth;
- iconRect.bottom += theInfo.descent;
-
- InsetRect(&iconRect, -1, -1);
-
- theHilightMode = LMGetHiliteMode();
- BitClr(&theHilightMode, pHiliteBit);
- LMSetHiliteMode(theHilightMode);
- InvertRect(&iconRect);
- }
-
- TextFont(applFont);
- TextSize(0);
- }
- break;
- }
- }
-
-